Fix non-iteratrable input of yieldEach#455
Fix non-iteratrable input of yieldEach#455Yi2255 wants to merge 1 commit intogoogleprojectzero:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
| } else { | ||
| // TODO only do this when the value is iterable? | ||
| b.yieldEach(val) | ||
| b.yieldEach(b.buildIteratorVariable(b, val)) |
There was a problem hiding this comment.
I think here it would make sense to split this into two generators:
CodeGenerator("YieldGenerator", inContext: .generatorFunction, inputs: .one) { b, val in
assert(b.context.contains(.generatorFunction))
if probability(0.9) {
b.yield(val)
} else {
b.yield()
}
},
CodeGenerator("YieldEachGenerator", inContext: .generatorFunction, inputs: .required(.iterable)) { b, val in
assert(b.context.contains(.generatorFunction))
b.yieldEach(val)
},
That way it's easy to guarantee that we get a .iterable.
| b.yield(b.randomVariable()) | ||
| } else { | ||
| b.yieldEach(b.randomVariable()) | ||
| b.yieldEach(b.buildIteratorVariable(b, it)) |
There was a problem hiding this comment.
Here and in the AsyncGeneratorFunctionGenerator, I would recommend doing this differently. For one, I think we would usually prefer to yield something that we create in this function (i.e. in the buildRecursive() call), but that's not possible if the it comes from the outside. I would probably recommend just doing something like this:
} else {
let randomVariables = b.randomVariables(Int.random(in: 1...5))
let array = b.createArray(with: randomVariables)
b.yieldEach(array)
}
This will then cause us to always yield a plain array, but we have the other CodeGenerator below for yielding other stuff. Also the InputMutator will quickly shuffle this around to yield from other things.
Logic:
CodeGeneratoris iterable, use it directly.yieldEachis an iterable object, thus eliminating the need for additionalguardchecks.